package com.xgst.land.dialog

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import com.blankj.utilcode.util.ConvertUtils
import com.xgst.land.R

abstract class BaseDialog(context: Context,width:Float = 300f,height:Float = 0f) : Dialog(context, R.style.dialogStyle) {
    var view:View
    init {
        view =
            LayoutInflater.from(context).inflate(getLayoutRes(), null, false)
        setContentView(view)
        val attributes = window!!.attributes
        attributes.height = if(height == 0f) ViewGroup.LayoutParams.WRAP_CONTENT else height.toInt()
        attributes.width= if(width == 0f) ViewGroup.LayoutParams.MATCH_PARENT else ConvertUtils.dp2px(width)
        window!!.attributes = attributes
        setCancelable(true)
    }

    @LayoutRes
    abstract fun getLayoutRes():Int

}